package com.cloudlinkscm.loms.services.base.notify.dto.email.builder.component;

import com.cloudlinkscm.loms.services.base.notify.dto.email.EmailMessageDto;
import com.cloudlinkscm.loms.services.base.notify.dto.email.builder.EmailMessageDtoBuilder;
import com.cloudlinkscm.loms.services.base.notify.dto.email.builder.EmailMessageDtoBuilderDecorator;

/**
 * @author : tac
 * @date : 2017/7/12
 */
public class EmailMessageDtoBodyBuilderDecorator extends EmailMessageDtoBuilderDecorator {

    private BodyEnum bodyEnum;
    private String body;

    public EmailMessageDtoBodyBuilderDecorator(EmailMessageDtoBuilder builder) {
        super(builder);
    }

    @Override
    public EmailMessageDto build() {
        EmailMessageDto dto = builder.build();

        switch (bodyEnum){
            case TEXT:
                dto.setBody(body);
                break;
            case LINK_URL:
                dto.setUrlHead(body);
                break;
        }
        return dto;
    }

    public EmailMessageDtoBodyBuilderDecorator text(String text){
        bodyEnum = BodyEnum.TEXT;
        this.body = text;
        return this;
    }
    public EmailMessageDtoBodyBuilderDecorator linkUrl(String url){
        bodyEnum = BodyEnum.LINK_URL;
        this.body = url;
        return this;
    }

    public EmailMessageDtoSendDateBuilderDecorator next(){
        return new EmailMessageDtoSendDateBuilderDecorator(this);
    }

    enum BodyEnum{
        TEXT,
        LINK_URL,
    }
}
